home *** CD-ROM | disk | FTP | other *** search
/ Hardcore Gamer Resource Kit / Hardcore Gamer Resource Kit - Disc 2.iso / Utils / UNIX / UNZIP520 / AMIGA / AMIGA.C next >
C/C++ Source or Header  |  1996-03-30  |  29KB  |  842 lines

  1. /*------------------------------------------------------------------------
  2.  
  3.   amiga.c
  4.  
  5.   Amiga-specific routines for use with Info-ZIP's UnZip 5.1 and later.
  6.   See History.5xx for revision history.
  7.  
  8.   Contents:   mapattr()
  9.               mapname()
  10.               do_wild()
  11.               checkdir()
  12.               close_outfile()
  13.               _abort()                (Aztec C only)
  14.              [dateformat()]           (currently not used)
  15.               windowheight()
  16.               version()
  17.  
  18.   ------------------------------------------------------------------------*/
  19.  
  20.  
  21. #define UNZIP_INTERNAL
  22. #include "unzip.h"
  23.  
  24. /* Globular varibundus -- now declared in SYSTEM_SPECIFIC_GLOBALS in amiga.h */
  25.  
  26. /* static int created_dir; */      /* used in mapname(), checkdir() */
  27. /* static int renamed_fullpath; */ /* ditto */
  28.  
  29. #define PERMS   0777
  30. #define MKDIR(path,mode) mkdir(path)
  31.  
  32.  
  33. #ifndef S_ISCRIPT          /* not having one implies you have none */
  34. #  define S_IARCHIVE 0020  /* not modified since this bit was last set */
  35. #  define S_IREAD    0010  /* can be opened for reading */
  36. #  define S_IWRITE   0004  /* can be opened for writing */
  37. #  define S_IDELETE  0001  /* can be deleted */
  38. #endif /* S_ISCRIPT */
  39.  
  40. #ifndef S_IRWD
  41. #  define S_IRWD     0015  /* useful combo of Amiga privileges */
  42. #endif /* !S_IRWD */
  43.  
  44. #ifndef S_IHIDDEN
  45. #  define S_IHIDDEN  0200  /* hidden supported in future AmigaDOS (someday) */
  46. #endif /* !S_HIDDEN */
  47.  
  48. #ifndef SFX
  49. /* Make sure the number here matches version.h in the *EXACT* form */
  50. /* UZ_MAJORVER "." UZ_MINORVER PATCHLEVEL vvvv     No non-digits!  */
  51. static char version_id[] = "\0$VER: UnZip 5.20 ("
  52. #  include "env:VersionDate"
  53. ")\r\n";
  54. #endif
  55.  
  56.  
  57. /**********************/
  58. /* Function mapattr() */
  59. /**********************/
  60.  
  61. int mapattr(__G)      /* Amiga version */
  62.     __GDEF
  63. {
  64.     ulg  tmp = G.crec.external_file_attributes;
  65.  
  66.  
  67.     /* Amiga attributes = hsparwed = hidden, script, pure, archive,
  68.      * read, write, execute, delete */
  69.  
  70.     switch (G.pInfo->hostnum) {
  71.         case AMIGA_:
  72.             if ((tmp & 1) == (tmp>>18 & 1))
  73.                 tmp ^= 0x000F0000;      /* PKAZip compatibility kluge */
  74.             /* turn off archive bit for restored Amiga files */
  75.             G.pInfo->file_attr = (unsigned)((tmp>>16) & (~S_IARCHIVE));
  76.             break;
  77.  
  78.         case UNIX_:   /* preserve read, write, execute:  use logical-OR of */
  79.         case VMS_:    /* user, group, and other; if writable, set delete bit */
  80.             tmp >>= 16;
  81.             tmp = (( tmp>>6 | tmp>>3 | tmp) & 07) << 1;
  82.             G.pInfo->file_attr = (unsigned)(tmp&S_IWRITE? tmp|S_IDELETE : tmp);
  83.             break;
  84.  
  85.         /* all other platforms:  assume read-only bit in DOS half of attribute
  86.          * word is set correctly ==> will become READ or READ+WRITE+DELETE */
  87.         case FS_FAT_:
  88.         case FS_HPFS_:  /* can add S_IHIDDEN check to MSDOS/OS2/NT eventually */
  89.         case FS_NTFS_:
  90.         case MAC_:
  91.         case ATARI_:
  92.         case TOPS20_:
  93.         default:
  94.             G.pInfo->file_attr = (unsigned)(tmp&1? S_IREAD : S_IRWD);
  95.             break;
  96.  
  97.     } /* end switch (host-OS-created-by) */
  98.  
  99.     G.pInfo->file_attr &= 0xff;   /* mask off all but lower eight bits */
  100.     return 0;
  101.  
  102. } /* end function mapattr() */
  103.  
  104.  
  105.  
  106.  
  107. /************************/
  108. /*  Function mapname()  */
  109. /************************/
  110.  
  111. int mapname(__G__ renamed)  /* return 0 if no error, 1 if caution (truncate), */
  112.     __GDEF                  /* 2 if warning (skip because dir doesn't exist), */
  113.     int renamed;            /* 3 if error (skip file), 10 if no memory (skip) */
  114. {
  115.     char pathcomp[FILNAMSIZ];   /* path-component buffer */
  116.     char *pp, *cp=NULL;         /* character pointers */
  117.     char *lastsemi = NULL;      /* pointer to last semi-colon in pathcomp */
  118.     int error = 0;
  119.     register unsigned workch;   /* hold the character being tested */
  120.  
  121.  
  122. /*---------------------------------------------------------------------------
  123.     Initialize various pointers and counters and stuff.
  124.   ---------------------------------------------------------------------------*/
  125.  
  126.     /* can create path as long as not just freshening, or if user told us */
  127.     G.create_dirs = (!G.fflag || renamed);
  128.  
  129.     G.created_dir = FALSE;      /* not yet */
  130.  
  131.     /* user gave full pathname:  don't prepend rootpath */
  132.     G.renamed_fullpath = (renamed && strchr(G.filename, ':'));
  133.  
  134.     if (checkdir(__G__ (char *)NULL, INIT) == 10)
  135.         return 10;              /* initialize path buffer, unless no memory */
  136.  
  137.     *pathcomp = '\0';           /* initialize translation buffer */
  138.     pp = pathcomp;              /* point to translation buffer */
  139.     if (G.jflag)                /* junking directories */
  140.         cp = (char *)strrchr(G.filename, '/');
  141.     if (cp == NULL)             /* no '/' or not junking dirs */
  142.         cp = G.filename;        /* point to internal zipfile-member pathname */
  143.     else
  144.         ++cp;                   /* point to start of last component of path */
  145.  
  146. /*---------------------------------------------------------------------------
  147.     Begin main loop through characters in filename.
  148.   ---------------------------------------------------------------------------*/
  149.  
  150.     while ((workch = (uch)*cp++) != 0) {
  151.  
  152.         switch (workch) {
  153.         case '/':             /* can assume -j flag not given */
  154.             *pp = '\0';
  155.             if ((error = checkdir(__G__ pathcomp, APPEND_DIR)) > 1)
  156.                 return error;
  157.             pp = pathcomp;    /* reset conversion buffer for next piece */
  158.             lastsemi = NULL;  /* leave directory semi-colons alone */
  159.             break;
  160.  
  161.         case ';':             /* VMS version (or DEC-20 attrib?) */
  162.             lastsemi = pp;         /* keep for now; remove VMS ";##" */
  163.             *pp++ = (char)workch;  /*  later, if requested */
  164.             break;
  165.  
  166.         default:
  167.             /* allow ISO European characters in filenames: */
  168.             if (isprint(workch) || (160 <= workch && workch <= 255))
  169.                 *pp++ = (char)workch;
  170.         } /* end switch */
  171.     } /* end while loop */
  172.  
  173.     *pp = '\0';                   /* done with pathcomp:  terminate it */
  174.  
  175.     /* if not saving them, remove with VMS version numbers (appended ";###") */
  176.     if (!G.V_flag && lastsemi) {
  177.         pp = lastsemi + 1;
  178.         while (isdigit((uch)(*pp)))
  179.             ++pp;
  180.         if (*pp == '\0')          /* only digits between ';' and end:  nuke */
  181.             *lastsemi = '\0';
  182.     }
  183.  
  184. /*---------------------------------------------------------------------------
  185.     Report if directory was created (and no file to create:  filename ended
  186.     in '/'), check name to be sure it exists, and combine path and name be-
  187.     fore exiting.
  188.   ---------------------------------------------------------------------------*/
  189.  
  190.     if (G.filename[strlen(G.filename) - 1] == '/') {
  191.         checkdir(__G__ G.filename, GETPATH);
  192.         if (G.created_dir && QCOND2) {
  193.             Info(slide, 0, ((char *)slide, "   creating: %s\n", G.filename));
  194.             return IZ_CREATED_DIR;   /* set dir time (note trailing '/') */
  195.         }
  196.         return 2;   /* dir existed already; don't look for data to extract */
  197.     }
  198.  
  199.     if (*pathcomp == '\0') {
  200.         Info(slide, 1, ((char *)slide, "mapname:  conversion of %s failed\n",
  201.              G.filename));
  202.         return 3;
  203.     }
  204.  
  205.     if ((error = checkdir(__G__ pathcomp, APPEND_NAME)) == 1) {
  206.         /* GRR:  OK if truncated here:  warn and continue */
  207.         /* (warn in checkdir?) */
  208.     }
  209.     checkdir(__G__ G.filename, GETPATH);
  210.  
  211.     return error;
  212.  
  213. } /* end function mapname() */
  214.  
  215.  
  216. static int ispattern(char *p)
  217. {
  218.     register char c;
  219.     while (c = *p++)
  220.         if (c == '\\') {
  221.             if (!*++p)
  222.                 return FALSE;
  223.         } else if (c == '?' || c == '*')
  224.             return TRUE;
  225.         else if (c == '[') {
  226.             for (;;) {
  227.                 if (!(c = *p++))
  228.                     return FALSE;
  229.                 else if (c == '\\') {
  230.                     if (!*++p)
  231.                         return FALSE;
  232.                 } else if (c == ']')
  233.                     return TRUE;
  234.             }
  235.         }
  236.     return FALSE;
  237. }
  238.  
  239. /**********************/
  240. /* Function do_wild() */
  241. /**********************/
  242.  
  243. char *do_wild(__G__ wildspec)
  244.     __GDEF
  245.     char *wildspec;         /* only used first time on a given dir */
  246. {
  247. /* these statics are now declared in SYSTEM_SPECIFIC_GLOBALS in amiga.h:
  248.     static DIR *wild_dir = NULL;
  249.     static char *dirname, *wildname, matchname[FILNAMSIZ];
  250.     static int notfirstcall = FALSE, dirnamelen;
  251. */
  252.     struct dirent *file;
  253.     BPTR lok = 0;
  254.     /* Even when we're just returning wildspec, we *always* do so in
  255.      * matchname[]--calling routine is allowed to append four characters
  256.      * to the returned string, and wildspec may be a pointer to argv[].
  257.      */
  258.     if (!G.notfirstcall) {      /* first call:  must initialize everything */
  259.         G.notfirstcall = TRUE;
  260.         /* avoid needless readdir() scans: */
  261.         if (!ispattern(wildspec) || (lok = Lock(wildspec, ACCESS_READ))) {
  262.             if (lok) UnLock(lok);       /* ^^ we ignore wildcard chars if */
  263.             G.dirnamelen = 0;           /* the name matches a real file   */
  264.             strcpy(G.matchname, wildspec);
  265.             return G.matchname;
  266.         }
  267.  
  268.         /* break the wildspec into a directory part and a wildcard filename */
  269.         if ((G.wildname = strrchr(wildspec, '/')) == NULL
  270.                         && (G.wildname = strrchr(wildspec, ':')) == NULL) {
  271.             G.dirname = "";             /* current dir */
  272.             G.dirnamelen = 0;
  273.             G.wildname = wildspec;
  274.         } else {
  275.             ++G.wildname;     /* point at character after '/' or ':' */
  276.             G.dirnamelen = G.wildname - wildspec;
  277.             if ((G.dirname = (char *)malloc(G.dirnamelen+1)) == NULL) {
  278.                 Info(slide, 1, ((char *)slide,
  279.                      "warning:  can't allocate wildcard buffers\n"));
  280.                 strcpy(G.matchname, wildspec);
  281.                 return G.matchname; /* but maybe filespec was not a wildcard */
  282.             }
  283.             strncpy(G.dirname, wildspec, G.dirnamelen);
  284.             G.dirname[G.dirnamelen] = 0;
  285.         }
  286.  
  287.         if ((G.wild_dir = opendir(G.dirname)) != NULL) {
  288.             while ((file = readdir(G.wild_dir)) != NULL) {
  289.                 if (match(file->d_name, G.wildname, 1)) {  /* ignore case */
  290.                     strcpy(G.matchname, G.dirname);
  291.                     strcpy(G.matchname + G.dirnamelen, file->d_name);
  292.                     return G.matchname;
  293.                 }
  294.             }
  295.             /* if we get to here directory is exhausted, so close it */
  296.             closedir(G.wild_dir);
  297.             G.wild_dir = NULL;
  298.         }
  299.  
  300.         /* return the raw wildspec in case that works (e.g., directory not
  301.          * searchable, but filespec was not wild and file is readable) */
  302.         strcpy(G.matchname, wildspec);
  303.         return G.matchname;
  304.     }
  305.  
  306.     /* last time through, might have failed opendir but returned raw wildspec */
  307.     if (G.wild_dir == NULL) {
  308.         G.notfirstcall = FALSE;    /* nothing left to try -- reset */
  309.         if (G.dirnamelen > 0)
  310.             free(G.dirname);
  311.         return (char *)NULL;
  312.     }
  313.  
  314.     /* If we've gotten this far, we've read and matched at least one entry
  315.      * successfully (in a previous call), so dirname has been copied into
  316.      * matchname already.
  317.      */
  318.     while ((file = readdir(G.wild_dir)) != NULL)
  319.         if (match(file->d_name, G.wildname, 1)) {   /* 1 == ignore case */
  320.             /* strcpy(G.matchname, dirname); */
  321.             strcpy(G.matchname + G.dirnamelen, file->d_name);
  322.             return G.matchname;
  323.         }
  324.  
  325.     closedir(G.wild_dir);  /* have read at least one dir entry; nothing left */
  326.     G.wild_dir = NULL;
  327.     G.notfirstcall = FALSE;  /* reset for new wildspec */
  328.     if (G.dirnamelen > 0)
  329.         free(G.dirname);
  330.     return (char *)NULL;
  331.  
  332. } /* end function do_wild() */
  333.  
  334.  
  335.  
  336. /***********************/
  337. /* Function checkdir() */
  338. /***********************/
  339.  
  340. int checkdir(__G__ pathcomp, flag)
  341.     __GDEF
  342.     char *pathcomp;
  343.     int flag;
  344. /*
  345.  * returns:  1 - (on APPEND_xxx) truncated path component
  346.  *           2 - path doesn't exist, not allowed to create
  347.  *           3 - path doesn't exist, tried to create and failed; or
  348.  *               path exists and is not a directory, but is supposed to be
  349.  *           4 - path is too long
  350.  *          10 - can't allocate memory for filename buffers
  351.  */
  352. {
  353.     static int rootlen = 0;   /* length of rootpath */
  354.     static char *rootpath;    /* user's "extract-to" directory */
  355.     static char *buildpath;   /* full path (so far) to extracted file */
  356.     static char *end;         /* pointer to end of buildpath ('\0') */
  357.  
  358. #   define FN_MASK   7
  359. #   define FUNCTION  (flag & FN_MASK)
  360.  
  361.  
  362.  
  363. /*---------------------------------------------------------------------------
  364.     APPEND_DIR:  append the path component to the path being built and check
  365.     for its existence.  If doesn't exist and we are creating directories, do
  366.     so for this one; else signal success or error as appropriate.
  367.   ---------------------------------------------------------------------------*/
  368.  
  369. /* GRR:  check path length after each segment:  warn about truncation */
  370.  
  371.     if (FUNCTION == APPEND_DIR) {
  372.         int too_long = FALSE;
  373.  
  374.         Trace((stderr, "appending dir segment [%s]\n", pathcomp));
  375.         while ((*end = *pathcomp++))
  376.             ++end;
  377.         /* Truncate components over 30 chars? Nah, the filesystem handles it. */
  378.         if ((end-buildpath) > FILNAMSIZ-3)  /* need '/', one-char name, '\0' */
  379.             too_long = TRUE;                /* check if extracting directory? */
  380.         if (stat(buildpath, &G.statbuf)) {  /* path doesn't exist */
  381.             if (!G.create_dirs) { /* told not to create (freshening) */
  382.                 free(buildpath);
  383.                 return 2;         /* path doesn't exist:  nothing to do */
  384.             }
  385.             if (too_long) {
  386.                 Info(slide, 1, ((char *)slide,
  387.                   "checkdir error:  path too long: %s\n", buildpath));
  388.                 free(buildpath);
  389.                 return 4;         /* no room for filenames:  fatal */
  390.             }
  391.             if (MKDIR(buildpath, 0777) == -1) {   /* create the directory */
  392.                 Info(slide, 1, ((char *)slide,
  393.                  "checkdir error:  can't create %s\n\
  394.                  unable to process %s.\n", buildpath, G.filename));
  395.                 free(buildpath);
  396.                 return 3;      /* path didn't exist, tried to create, failed */
  397.             }
  398.             G.created_dir = TRUE;
  399.         } else if (!S_ISDIR(G.statbuf.st_mode)) {
  400.             Info(slide, 1, ((char *)slide,
  401.                  "checkdir error:  %s exists but is not a directory\n\
  402.                  unable to process %s.\n", buildpath, G.filename));
  403.             free(buildpath);
  404.             return 3;          /* path existed but wasn't dir */
  405.         }
  406.         if (too_long) {
  407.             Info(slide, 1, ((char *)slide,
  408.                  "checkdir error:  path too long: %s\n", buildpath));
  409.             free(buildpath);
  410.             return 4;         /* no room for filenames:  fatal */
  411.         }
  412.         *end++ = '/';
  413.         *end = '\0';
  414.         Trace((stderr, "buildpath now = [%s]\n", buildpath));
  415.         return 0;
  416.  
  417.     } /* end if (FUNCTION == APPEND_DIR) */
  418.  
  419. /*---------------------------------------------------------------------------
  420.     GETPATH:  copy full path to the string pointed at by pathcomp, and free
  421.     buildpath.  Not our responsibility to worry whether pathcomp has room.
  422.   ---------------------------------------------------------------------------*/
  423.  
  424.     if (FUNCTION == GETPATH) {
  425.         strcpy(pathcomp, buildpath);
  426.         Trace((stderr, "getting and freeing path [%s]\n", pathcomp));
  427.         free(buildpath);
  428.         buildpath = end = NULL;
  429.         return 0;
  430.     }
  431.  
  432. /*---------------------------------------------------------------------------
  433.     APPEND_NAME:  assume the path component is the filename; append it and
  434.     return without checking for existence.
  435.   ---------------------------------------------------------------------------*/
  436.  
  437.     if (FUNCTION == APPEND_NAME) {
  438.         Trace((stderr, "appending filename [%s]\n", pathcomp));
  439.         while ((*end = *pathcomp++)) {
  440.             ++end;
  441.             if ((end-buildpath) >= FILNAMSIZ) {
  442.                 *--end = '\0';
  443.                 Info(slide, 1, ((char *)slide,
  444.                    "checkdir warning:  path too long; truncating\n\
  445.                    %s\n                -> %s\n", G.filename, buildpath));
  446.                 return 1;   /* filename truncated */
  447.             }
  448.         }
  449.         Trace((stderr, "buildpath now = [%s]\n", buildpath));
  450.         return 0;  /* could check for existence here, prompt for new name... */
  451.     }
  452.  
  453. /*---------------------------------------------------------------------------
  454.     INIT:  allocate and initialize buffer space for the file currently being
  455.     extracted.  If file was renamed with an absolute path, don't prepend the
  456.     extract-to path.
  457.   ---------------------------------------------------------------------------*/
  458.  
  459.     if (FUNCTION == INIT) {
  460.         Trace((stderr, "initializing buildpath to "));
  461.         if ((buildpath = (char *)malloc(strlen(G.filename)+rootlen+1)) == NULL)
  462.             return 10;
  463.         if ((rootlen > 0) && !G.renamed_fullpath) {
  464.             strcpy(buildpath, rootpath);
  465.             end = buildpath + rootlen;
  466.         } else {
  467.             *buildpath = '\0';
  468.             end = buildpath;
  469.         }
  470.         Trace((stderr, "[%s]\n", buildpath));
  471.         return 0;
  472.     }
  473.  
  474. /*---------------------------------------------------------------------------
  475.     ROOT:  if appropriate, store the path in rootpath and create it if neces-
  476.     sary; else assume it's a zipfile member and return.  This path segment
  477.     gets used in extracting all members from every zipfile specified on the
  478.     command line.
  479.   ---------------------------------------------------------------------------*/
  480.  
  481. #if (!defined(SFX) || defined(SFX_EXDIR))
  482.     if (FUNCTION == ROOT) {
  483.         Trace((stderr, "initializing root path to [%s]\n", pathcomp));
  484.         if (pathcomp == NULL) {
  485.             rootlen = 0;
  486.             return 0;
  487.         }
  488.         if ((rootlen = strlen(pathcomp)) > 0) {
  489.             if (stat(pathcomp, &G.statbuf) || !S_ISDIR(G.statbuf.st_mode)) {
  490.                 /* path does not exist */
  491.                 if (!G.create_dirs) {
  492.                     rootlen = 0;
  493.                     return 2;   /* treat as stored file */
  494.                 }
  495.                 /* create the directory (could add loop here to scan pathcomp
  496.                  * and create more than one level, but why really necessary?) */
  497.                 if (MKDIR(pathcomp, 0777) == -1) {
  498.                     Info(slide, 1, ((char *)slide,
  499.                          "checkdir:  can't create extraction directory: %s\n",
  500.                          pathcomp));
  501.                     rootlen = 0;   /* path didn't exist, tried to create, and */
  502.                     return 3;  /* failed:  file exists, or 2+ levels required */
  503.                 }
  504.             }
  505.             if ((rootpath = (char *)malloc(rootlen+2)) == NULL) {
  506.                 rootlen = 0;
  507.                 return 10;
  508.             }
  509.             strcpy(rootpath, pathcomp);
  510.             if (rootpath[rootlen - 1] != ':' && rootpath[rootlen - 1] != '/')
  511.                 rootpath[rootlen++] = '/';
  512.             rootpath[rootlen] = '\0';
  513.             Trace((stderr, "rootpath now = [%s]\n", rootpath));
  514.         }
  515.         return 0;
  516.     }
  517. #endif /* !SFX || SFX_EXDIR */
  518.  
  519. /*---------------------------------------------------------------------------
  520.     END:  free rootpath, immediately prior to program exit.
  521.   ---------------------------------------------------------------------------*/
  522.  
  523.     if (FUNCTION == END) {
  524.         Trace((stderr, "freeing rootpath\n"));
  525.         if (rootlen > 0)
  526.             free(rootpath);
  527.         return 0;
  528.     }
  529.  
  530.     return 99;  /* should never reach */
  531.  
  532. } /* end function checkdir() */
  533.  
  534.  
  535. /**************************************/
  536. /* Function close_outfile() */
  537. /**************************************/
  538. /* this part differs slightly with Zip */
  539. /*-------------------------------------*/
  540.  
  541. void close_outfile(__G)
  542.     __GDEF
  543. {
  544.     time_t m_time;
  545. #ifdef USE_EF_UX_TIME
  546.     ztimbuf z_utime;
  547. #endif
  548.     LONG FileDate();
  549.  
  550.     if (G.cflag)                /* can't set time or filenote on stdout */
  551.         return;
  552.  
  553.   /* close the file *before* setting its time under AmigaDos */
  554.  
  555.     fclose(G.outfile);
  556.  
  557. #ifdef USE_EF_UX_TIME
  558.     if (G.extra_field &&
  559.         ef_scan_for_izux(G.extra_field, G.lrec.extra_field_length,
  560.                          &z_utime, NULL) > 0) {
  561.         TTrace((stderr, "close_outfile:  Unix e.f. modif. time = %ld\n",
  562.                          z_utime.modtime));
  563.         m_time = z_utime.modtime;
  564.     } else {
  565.         /* Convert DOS time to time_t format */
  566.         m_time = dos_to_unix_time(G.lrec.last_mod_file_date,
  567.                                   G.lrec.last_mod_file_time);
  568.     }
  569. #else /* !USE_EF_UX_TIME */
  570.     /* Convert DOS time to time_t format */
  571.     m_time = dos_to_unix_time(G.lrec.last_mod_file_date,
  572.                               G.lrec.last_mod_file_time);
  573. #endif /* ?USE_EF_UX_TIME */
  574.  
  575. #ifdef DEBUG
  576.     Info(slide, 1, (slide, "\nclose_outfile(): m_time=%s\n", ctime(&m_time));
  577. #endif
  578.  
  579.     if (!FileDate(G.filename, &m_time))
  580.         Info(slide, 1, ((char *)slide,
  581.              "warning:  can't set the time for %s\n", G.filename));
  582.  
  583.   /* set file perms after closing (not done at creation)--see mapattr() */
  584.  
  585.     chmod(G.filename, G.pInfo->file_attr);
  586.  
  587.   /* give it a filenote from the zipfile comment, if appropriate */
  588.  
  589.     if (G.N_flag && G.filenotes[G.filenote_slot]) {
  590.         SetComment(G.filename, G.filenotes[G.filenote_slot]);
  591.         free(G.filenotes[G.filenote_slot]);
  592.         G.filenotes[G.filenote_slot] = NULL;
  593.     }
  594.  
  595. } /* end function close_outfile() */
  596.  
  597.  
  598. /********************************************************************/
  599. /* Load filedate as a separate external file; it's used by Zip, too.*/
  600. /*                                                                  */
  601. #include "amiga/filedate.c"                                      /* */
  602. /*                                                                  */
  603. /********************************************************************/
  604.  
  605. /**************** for Aztec, do linewise with stat.c ****************/
  606.  
  607. #ifdef AZTEC_C
  608. #  include "amiga/stat.c"
  609. /* this is the exact same stat.c used for Aztec by Zip */
  610.  
  611. #  include <stdio.h>
  612.  
  613. void _abort(void)               /* called when ^C is pressed */
  614. {
  615.     /* echon(); */
  616.     close_leftover_open_dirs();
  617.     fflush(stdout);
  618.     fputs("\n^C\n", stderr);
  619.     exit(1);
  620. }
  621. #endif /* AZTEC_C */
  622.  
  623.  
  624. /**************************************************************/
  625. /* function windowheight() -- uses sendpkt() from filedate.c: */
  626. /**************************************************************/
  627.  
  628. #include <devices/conunit.h>
  629. #include <dos/dosextens.h>
  630. #include <exec/memory.h>
  631. #include <clib/exec_protos.h>
  632.  
  633. extern long sendpkt(struct MsgPort *pid, long action, long *args, long nargs);
  634.  
  635. int windowheight(BPTR fh)
  636. {
  637.     if (fh && IsInteractive(fh)) {
  638.         struct ConUnit *conunit = NULL;
  639.         void *conp = ((struct FileHandle *) (fh << 2))->fh_Type;
  640.         struct InfoData *ind = AllocMem(sizeof(*ind), MEMF_PUBLIC);
  641.         long argp = ((unsigned long) ind) >> 2;
  642.  
  643.         if (ind && conp && sendpkt(conp, ACTION_DISK_INFO, &argp, 1))
  644.             conunit = (void *) ((struct IOStdReq *) ind->id_InUse)->io_Unit;
  645.         if (ind)
  646.             FreeMem(ind, sizeof(*ind));
  647.         if (conunit)
  648.             return conunit->cu_YMax + 1;
  649.     }
  650.     return MAXINT;
  651. }
  652.  
  653.  
  654. #ifdef AMIGA_VOLUME_LABELS
  655. /* This function is for if we someday implement -$ on the Amiga. */
  656. #  include <dos/dosextens.h>
  657. #  include <dos/filehandler.h>
  658. #  include <clib/macros.h>
  659.  
  660. BOOL is_floppy(char *path)
  661. {
  662.     BOOL okay = FALSE;
  663.     char devname[32], *debna;
  664.     ushort i;
  665.     BPTR lok = Lock(path, ACCESS_READ), pok;
  666.     struct FileSysStartupMsg *fart;
  667.     struct DeviceNode *debb, devlist = (void *) BADDR((struct DosInfo *)
  668.                                 BADDR(DOSBase->dl_Root->rn_Info)->di_DevInfo);
  669.     if (!lok)
  670.         return FALSE;                   /* should not happen */
  671.     if (pok = ParentDir(path)) {
  672.         UnLock(lok);
  673.         UnLock(pok);
  674.         return FALSE;                   /* it's not a root directory path */
  675.     }
  676.     Forbid();
  677.     for (debb = devlist; debb; debb = BADDR(debb->dn_Next))
  678.         if (debb->dn_Type == DLT_DEVICE && (debb->dn_Task == lick->fl_Task))
  679.             if (fart = BADDR(debb->dn_Startup)) {
  680.                 debna = (char *) BADDR(fart->fssm_Device) + 1;
  681.                 if ((i = debna[-1]) > 31) i = 30;
  682.                 strncpy(devname, debna, i);
  683.                 devname[i] = 0;
  684.                 okay = !strcmp(devname, "trackdisk.device")
  685.                                 || !strcmp(devname, "mfm.device")
  686.                                 || !strcmp(devname, "messydisk.device");
  687.                 break;  /* We only support obvious floppy drives, not tricky */
  688.             }           /* things like removable cartrige hard drives, or    */
  689.     Permit();           /* any unusual kind of floppy device driver.         */
  690.     return okay;
  691. }
  692. #endif /* AMIGA_VOLUME_LABELS */
  693.  
  694.  
  695. #ifndef SFX
  696.  
  697. # if 0
  698. /* As far as I can tell, all the locales AmigaDOS 2.1 knows about all */
  699. /* happen to use DF_MDY ordering, so there's no point in using this.  */
  700.  
  701. /*************************/
  702. /* Function dateformat() */
  703. /*************************/
  704.  
  705. #include <clib/locale_protos.h>
  706. #ifdef AZTEC_C
  707. #  include <pragmas/locale_lib.h>
  708. #endif
  709.  
  710. int dateformat()
  711. {
  712. /*---------------------------------------------------------------------------
  713.     For those operating systems which support it, this function returns a
  714.     value which tells how national convention says that numeric dates are
  715.     displayed.  Return values are DF_YMD, DF_DMY and DF_MDY (the meanings
  716.     should be fairly obvious).
  717.   ---------------------------------------------------------------------------*/
  718.     struct Library *LocaleBase;
  719.     struct Locale *ll;
  720.     int result = DF_MDY;        /* the default */
  721.  
  722.     if ((LocaleBase = OpenLibrary("locale.library", 0))) {
  723.         if (ll = OpenLocale(NULL)) {
  724.             uch *f = ll->loc_ShortDateFormat;
  725.             /* In this string, %y|%Y is year, %b|%B|%h|%m is month, */
  726.             /* %d|%e is day day, and %D|%x is short for mo/da/yr.   */
  727.             if (!strstr(f, "%D") && !strstr(f, "%x")) {
  728.                 uch *da, *mo, *yr;
  729.                 if (!(mo = strstr(f, "%b")) && !(mo = strstr(f, "%B"))
  730.                                     && !(mo = strstr(f, "%h")))
  731.                     mo = strstr(f, "%m");
  732.                 if (!(da = strstr(f, "%d")))
  733.                     da = strstr(f, "%e");
  734.                 if (!(yr = strstr(f, "%y")))
  735.                     yr = strstr(f, "%Y");
  736.                 if (yr && yr < mo)
  737.                     result = DF_YMD;
  738.                 else if (da && da < mo)
  739.                     result = DF_DMY;
  740.             }
  741.             CloseLocale(ll);
  742.         }
  743.         CloseLibrary(LocaleBase);
  744.     }
  745.     return result;
  746. }
  747.  
  748. # endif /* 0 */
  749.  
  750.  
  751. /************************/
  752. /*  Function version()  */
  753. /************************/
  754.  
  755.  
  756. /* NOTE:  the following include depends upon the environment
  757.  *        variable $Workbench to be set correctly.  (Set by
  758.  *        default, by kickstart during startup)
  759.  */
  760. int WBversion = (int)
  761. #include "ENV:Workbench"
  762. ;
  763.  
  764. void version(__G)
  765.    __GDEF
  766. {
  767. /* Define buffers. */
  768.  
  769.    char buf1[16];  /* compiler name */
  770.    char buf2[16];  /* revstamp */
  771.    char buf3[16];  /* OS */
  772.    char buf4[16];  /* Date */
  773. /*   char buf5[16];  /* Time */
  774.  
  775. /* format "with" name strings */
  776.  
  777. #ifdef AMIGA
  778. # ifdef __SASC
  779.    strcpy(buf1,"SAS/C ");
  780. # else
  781. #  ifdef LATTICE
  782.     strcpy(buf1,"Lattice C ");
  783. #  else
  784. #   ifdef AZTEC_C
  785.      strcpy(buf1,"Manx Aztec C ");
  786. #   else
  787.      strcpy(buf1,"UNKNOWN ");
  788. #   endif
  789. #  endif
  790. # endif
  791. /* "under" */
  792.   sprintf(buf3,"AmigaDOS v%d",WBversion);
  793. #else
  794.   strcpy(buf1,"Unknown compiler ");
  795.   strcpy(buf3,"Unknown OS");
  796. #endif
  797.  
  798. /* Define revision, date, and time strings.
  799.  * NOTE:  Do not calculate run time, be sure to use time compiled.
  800.  * Pass these strings via your makefile if undefined.
  801.  */
  802.  
  803. #if defined(__VERSION__) && defined(__REVISION__)
  804.   sprintf(buf2,"version %d.%d",__VERSION__,__REVISION__);
  805. #else
  806. # ifdef __VERSION__
  807.   sprintf(buf2,"version %d",__VERSION__);
  808. # else
  809.   sprintf(buf2,"unknown version");
  810. # endif
  811. #endif
  812.  
  813. #ifdef __DATE__
  814.   sprintf(buf4," on %s",__DATE__);
  815. #else
  816.   strcpy(buf4," unknown date");
  817. #endif
  818.  
  819. /******
  820. #ifdef __TIME__
  821.   sprintf(buf5," at %s",__TIME__);
  822. #else
  823.   strcpy(buf5," unknown time");
  824. #endif
  825. ******/
  826.  
  827. /* Print strings using "CompiledWith" mask defined in unzip.c (used by all).
  828.  *  ("Compiled with %s%s under %s%s%s%s.")
  829.  */
  830.  
  831.    printf(LoadFarString(CompiledWith),
  832.      buf1,
  833.      buf2,
  834.      buf3,
  835.      buf4,
  836.      "",    /* buf5 not used */
  837.      "" );  /* buf6 not used */
  838.  
  839. } /* end function version() */
  840.  
  841. #endif /* !SFX */
  842.